package com.estore.service;

import com.estore.model.Product;
import java.util.Comparator;

public class ProductSorters {
    public static  final Comparator<Product> BY_PRICE_ASC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Double.compare(p1.getPrice(),p2.getPrice());
        }
    };
    public  static  final Comparator<Product> BY_PRICE_DESC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Double.compare(p2.getPrice(),p1.getPrice());
        }
    };
    public  static  final Comparator<Product> BY_STOCK_DESC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Integer.compare(p2.getStock(),p1.getStock());
        }
    };
}
